package com.clickhouse_test.app.mapper.clickhouse;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Mapper
@Repository("ClickhouseMapper")
public interface ClickhouseMapper {
//    @Select("select count(*) ClickhouseCount from log_inspection_journal_column")
//    Integer getClickhouse();

    @Select("select * from producer")
    List<Map<String, String>> getClickhouse();

    @Select("select catalog_code,error_code,error,inspection_date,field_name,max(inserttime) inserttime,count(1) num " +
            " from log_inspection_journal_column " +
            " where catalog_code = #{CATALOG_CODE} and inspection_date = toDateTime(#{INSPECTION_DATE}) " +
            " group by catalog_code,error_code, error,inspection_date,field_name")
    List<Map<String, String>> getLog_inspection_journal_column(String CATALOG_CODE, String INSPECTION_DATE);

    @Select("<script>" +
            "select data_uuid " +
            " from log_inspection_journal_column" +
            " where catalog_code = #{CATALOG_CODE} and inspection_date = toDateTime(#{INSPECTION_DATE}) " +
            " <if test=\"ERROR_CODE != null and ERROR_CODE != ''\"> " +
            " and error_code = #{ERROR_CODE}" +
            " </if>" +
            " <if test=\"FIELD_NAME != null and FIELD_NAME != ''\"> " +
            " and field_name = #{FIELD_NAME}" +
            " </if>" +
            "</script>")
    List<Map<String, String>> getLogData_uuid(String CATALOG_CODE, String INSPECTION_DATE, String ERROR_CODE, String FIELD_NAME);
}
